package org.bigdata.framework.core.controller;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bigdata.framework.admin.web.ueditor.ActionEnter;
import org.bigdata.framework.core.model.Advertisement;
import org.bigdata.framework.core.model.Answer;
import org.bigdata.framework.core.model.Audit;
import org.bigdata.framework.core.model.Browse;
import org.bigdata.framework.core.model.Category;
import org.bigdata.framework.core.model.ClassesOnline;
import org.bigdata.framework.core.model.ClassesOnlineComment;
import org.bigdata.framework.core.model.Collect;
import org.bigdata.framework.core.model.Comment;
import org.bigdata.framework.core.model.Config;
import org.bigdata.framework.core.model.Course;
import org.bigdata.framework.core.model.CourseComment;
import org.bigdata.framework.core.model.CourseQuestion;
import org.bigdata.framework.core.model.Live;
import org.bigdata.framework.core.model.LiveQuestion;
import org.bigdata.framework.core.model.Log;
import org.bigdata.framework.core.model.Member;
import org.bigdata.framework.core.model.Message;
import org.bigdata.framework.core.model.Online;
import org.bigdata.framework.core.model.OnlineQuestion;
import org.bigdata.framework.core.model.Order;
import org.bigdata.framework.core.model.Paper;
import org.bigdata.framework.core.model.Question;
import org.bigdata.framework.core.model.QuestionDatabase;
import org.bigdata.framework.core.model.ShortFilm;
import org.bigdata.framework.core.model.ShortFilmComment;
import org.bigdata.framework.core.model.User;
import org.bigdata.framework.core.protocol.IBaseService;
import org.bigdata.framework.core.protocol.IPublicService;
import org.bigdata.framework.core.utils.FileDownloadUtil;
import org.bigdata.framework.core.utils.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import net.sf.json.JSONObject;
import springfox.documentation.annotations.ApiIgnore;


@ApiIgnore
@Controller
public class GetController extends BaseController{

	@Autowired
	private IBaseService baseService;
	@Autowired
	private IPublicService publicService;
	
	private static String FILESERVER = "";
	private static String FILEPATH = "";

	static {
		Properties properties_config = new Properties();
		InputStream in_config = GetController.class.getClassLoader().getResourceAsStream("config.properties");
		try {
			properties_config.load(in_config);

			FILESERVER = properties_config.getProperty("file.server");
			FILEPATH = properties_config.getProperty("file.path");
		} catch (IOException e) {
		}
	}
	
	@RequestMapping("userList")
	@ResponseBody
	public void userList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getUserCount(queryParams);
		List<User> list = publicService.getUser(queryParams, pageSize,pageNumber);
		for (User user : list) {
			user.setPassword("");
		}
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("teacherList")
	@ResponseBody
	public void teacherList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String username = request.getParameter("username");
		String telephone = request.getParameter("telephone");
		
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (username != null && !"".equals(username)) {
			queryParams.put("=,username", username);
		}
		if (telephone != null && !"".equals(telephone)) {
			queryParams.put("=,telephone", telephone);
		}
		queryParams.put("=,type", "1");
		queryParams.put("^,id", "desc");
		Integer count = publicService.getUserCount(queryParams);
		List<User> list = publicService.getUser(queryParams, pageSize,pageNumber);
		for (User user : list) {
			user.setPassword("");
		}
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("userFind")
	@ResponseBody
	public void userFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String type = request.getParameter("type");
		
		List<User>list=new ArrayList<User>();
		if (id != null && !"".equals(id)) {
			if("course".equals(type)){
				Course course = publicService.findCourse(Integer.parseInt(id));
				String[] splits = course.getUserIds().split(";");
				for (String string : splits) {
					if(!"".equals(string)){
						User user = publicService.findUser(Integer.parseInt(string));
						user.setPassword("");
						list.add(user);
					}
				}
			}else if("classesOnline".equals(type)){
				ClassesOnline course = publicService.findClassesOnline(Integer.parseInt(id));
				String[] splits = course.getUserIds().split(";");
				for (String string : splits) {
					if(!"".equals(string)){
						User user = publicService.findUser(Integer.parseInt(string));
						user.setPassword("");
						list.add(user);
					}
				}
			}
			
		}
		String result = super.formatToJson(list);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("advertisementList")
	@ResponseBody
	public void advertisementList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String name = request.getParameter("name");
		String auditType = request.getParameter("auditType");
		String status = request.getParameter("status");

		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name", name);
		}
		if (auditType != null && !"".equals(auditType)) {
			queryParams.put("=,auditType", auditType);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		User user1 = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		if(!user1.getUsername().equals("root")&&user1.getType()!=0){
			queryParams.put("=,createUser" , user1.getUsername());
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getAdvertisementCount(queryParams);
		List<Advertisement> advertisements = publicService.getAdvertisement(queryParams, pageSize,pageNumber);

		
		List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
		for (Advertisement advertisement : advertisements) {
			m=new HashMap<String, Object>();
			m.put("id", advertisement.getId());
			m.put("createTime", advertisement.getCreateTime());
			m.put("createUser", advertisement.getCreateUser());
			m.put("name", advertisement.getName());
			m.put("startTime", advertisement.getStartTime());
			m.put("endTime", advertisement.getEndTime());
			m.put("status", advertisement.getStatus());
			m.put("submitTime", advertisement.getSubmitTime());
			m.put("type", advertisement.getType());
			m.put("filePath", FILESERVER+advertisement.getFilePath());
			m.put("showTime", advertisement.getShowTime());
			m.put("sort", advertisement.getSort());
			m.put("auditType", advertisement.getAuditType());
			Integer courseId = advertisement.getCourseId();
			Course course = publicService.findCourse(courseId);
			m.put("courseName", course.getName());
			lm.add(m);
			m=null;
		}
		
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = lm.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("advertisementFind")
	@ResponseBody
	public void advertisementFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		Advertisement advertisement = new Advertisement();
		Map<String,Object>m=new HashMap<String, Object>();
		if (id != null && !"".equals(id)) {
			advertisement = publicService.findAdvertisement(Integer.parseInt(id));
			m.put("id", advertisement.getId());
			m.put("endTime", advertisement.getEndTime());
			m.put("startTime", advertisement.getStartTime());
			m.put("filePath", FILESERVER+advertisement.getFilePath());
			m.put("name", advertisement.getName());
			m.put("showTime", advertisement.getShowTime());
			m.put("sort", advertisement.getSort());
			m.put("type", advertisement.getType());
			Integer courseId = advertisement.getCourseId();
			Course course = publicService.findCourse(courseId);
			m.put("courseName", course.getName());
			m.put("courseId", courseId);
			course=null;
		}
		
		String result = formatToJson(m);
		
		super.pringWriterToPage(result, "application/json", response);
	}
	@RequestMapping("browseList")
	@ResponseBody
	public void browseList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getBrowseCount(queryParams);
		List<Browse> list = publicService.getBrowse(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("categoryList")
	@ResponseBody
	public void categoryList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String name = request.getParameter("name");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name", name);
		}
		queryParams.put("^,sort", "asc");
		Integer count = publicService.getCategoryCount(queryParams);
		List<Category> list = publicService.getCategory(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("categoryAllList")
	@ResponseBody
	public void categoryAllList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<Category> list = publicService.getCategory();
		String result = formatToJson(list);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	/*@RequestMapping("categoryFind")
	@ResponseBody
	public void categoryFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String name = request.getParameter("name");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		HashMap<String, Object> r = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("=,name" , name);
			List<Category> list = publicService.getCategory(queryParams, 1,1);
			if(list!=null && list.size()>0){
				r.put("data", list.get(0));
			}
		}
		String result = super.formatToJson(r);
		super.pringWriterToPage(result, "application/json", response);
	}*/
	@RequestMapping("classesOnlineList")
	@ResponseBody
	public void classesOnlineList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String name = request.getParameter("name");
		String tag = request.getParameter("tag");
		String status = request.getParameter("status");
		String auditType = request.getParameter("auditType");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name", name);
		}
		if (tag != null && !"".equals(tag)) {
			queryParams.put("%,tag", tag);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		if (auditType != null && !"".equals(auditType)) {
			queryParams.put("=,auditType", auditType);
		}
		User user1 = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		if(!user1.getUsername().equals("root")&&user1.getType()!=0){
			queryParams.put("=,createUser" , user1.getUsername());
		}
		queryParams.put("^,id", "desc");
		List<Map<String, Object>>lm=new ArrayList<Map<String,Object>>();
		Integer count = publicService.getClassesOnlineCount(queryParams);
		List<ClassesOnline> list = publicService.getClassesOnline(queryParams, pageSize,pageNumber);
		for (ClassesOnline classesOnline : list) {
			Map<String, Object> m = new HashMap<String, Object>();
			m.put("id", classesOnline.getId());
			m.put("name", classesOnline.getName());
			m.put("description", classesOnline.getDescription());
			m.put("status", classesOnline.getStatus());
			m.put("tag", classesOnline.getTag());
			m.put("auditType", classesOnline.getAuditType());
			m.put("cover", FILESERVER+classesOnline.getCover());
			String userIds = classesOnline.getUserIds();
			String[] split = userIds.split(";");
			StringBuffer u = new StringBuffer();
			for (String string : split) {
				if(!"".equals(string)){
					User user = publicService.findUser(Integer.parseInt(string));
					if(user.getRealName()!=null && !"".equals(user.getRealName())){
						u.append(user.getRealName()).append(";");
					}else{
						u.append(user.getUsername()).append(";");
					}
					user=null;
				}
			}
			m.put("userIds", u.toString());
			lm.add(m);
			m=null;
		}
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("classesOnlineListPass")
	@ResponseBody
	public void classesOnlineListPass(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		List<ClassesOnline>list = new ArrayList<ClassesOnline>();
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		/*queryParams.put("=,status", "2");
		queryParams.put("=,auditType", "0");
		List<Map<String, Object>>lm=new ArrayList<Map<String,Object>>();
		Integer count = publicService.getClassesOnlineCount(queryParams);
		List<ClassesOnline> list1 = publicService.getClassesOnline(queryParams, 1,count);
		
		if(list1!=null){
			list.addAll(list1);
		}*/
		
		queryParams=null;
		queryParams = new HashMap<String, Object>();
		queryParams.put("=,status", "2");
		queryParams.put("=,auditType", "2");
		Integer count = publicService.getClassesOnlineCount(queryParams);
		List<ClassesOnline> list2 = publicService.getClassesOnline(queryParams, 1,count);
		if(list2!=null){
			list.addAll(list2);
		}
		
		String result = formatToJson(list);
		super.pringWriterToPage(result, "application/json", response);
	}
	@RequestMapping("classesOnlineFind")
	@ResponseBody
	public void classesOnlineFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		ClassesOnline classesOnline = new ClassesOnline();
		if (id != null && !"".equals(id)) {
			classesOnline = publicService.findClassesOnline(Integer.parseInt(id));
		}
		Map<String, Object>m=new HashMap<String, Object>();
		Map<String, Object>m1=new HashMap<String, Object>();
		String[] splits = classesOnline.getUserIds().split(";");
		
		for (String string : splits) {
			if(!"".equals(string)){
				User user = publicService.findUser(Integer.parseInt(string));
				if(user.getRealName()!=null && !"".equals(user.getRealName())){
					m1.put(user.getId()+"", user.getRealName());
				}else{
					m1.put(user.getId()+"", user.getUsername());
					
				}
			}
		}
		m.put("cover", FILESERVER+classesOnline.getCover());
		m.put("description", classesOnline.getDescription()==null?"":classesOnline.getDescription().replace(" src=\"", " src=\""+FILESERVER));
		m.put("name", classesOnline.getName());
		m.put("tag", classesOnline.getTag());
		m.put("userIds", m1);
		String sb = super.formatToJson(m);
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("classesOnlineCommentList")
	@ResponseBody
	public void classesOnlineCommentList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String classesOnlineId = request.getParameter("classesOnlineId");
		String content = request.getParameter("content");
		String telephone = request.getParameter("telephone");
		
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (classesOnlineId != null && !"".equals(classesOnlineId)) {
			queryParams.put("=,classesOnlineId", classesOnlineId);
		}
		if (content != null && !"".equals(content)) {
			queryParams.put("%,content", content);
		}
		if (telephone != null && !"".equals(telephone)) {
			queryParams.put("=,telephone", telephone);
		}
		
		queryParams.put("^,id", "desc");
		Integer count = publicService.getClassesOnlineCommentCount(queryParams);
		List<ClassesOnlineComment> list = publicService.getClassesOnlineComment(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("collectList")
	@ResponseBody
	public void collectList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getCollectCount(queryParams);
		List<Collect> list = publicService.getCollect(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("commentList")
	@ResponseBody
	public void commentList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String telephone = request.getParameter("telephone");
		String content = request.getParameter("content");
		String contact = request.getParameter("contact");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (telephone != null && !"".equals(telephone)) {
			queryParams.put("=,telephone", telephone);
		}
		if (contact != null && !"".equals(contact)) {
			queryParams.put("=,contact", contact);
		}
		if (content != null && !"".equals(content)) {
			queryParams.put("%,content", content);
		}
		if (startTime != null && !"".equals(startTime)) {
			queryParams.put(">=,createTime", startTime);
		}
		if (endTime != null && !"".equals(endTime)) {
			queryParams.put("<=,createTime", endTime);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getCommentCount(queryParams);
		List<Comment> list = publicService.getComment(queryParams, pageSize,pageNumber);
		List<Map<String, Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String, Object>m=null;
		for (Comment comment : list) {
			m=new HashMap<String, Object>();
			m.put("id", comment.getId());
			m.put("telephone", comment.getTelephone());
			m.put("contact", comment.getContact());
			m.put("content", comment.getContent());
			m.put("createTime", comment.getCreateTime());
			m.put("feedback", comment.getFeedback());
			m.put("status", comment.getStatus());
			m.put("createUser", comment.getCreateUser());
			m.put("memberId", comment.getMemberId());
			if(comment.getMemberId()!=null){
				Member member = publicService.findMember(comment.getMemberId());
				if(member!=null){
					m.put("avatarImg", FILESERVER+member.getAvatarImg());
				}else{
					m.put("avatarImg", "");
				}
				member=null;
			}else{
				m.put("avatarImg", "");
			}
			lm.add(m);
			m=null;
		}
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("commentFind")
	@ResponseBody
	public void commentFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		Map<String, Object>m = new HashMap<String, Object>();
		Comment comment = new Comment();
		if (id != null && !"".equals(id)) {
			comment=publicService.findComment(Integer.parseInt(id));
		}
		
		m.put("id", comment.getId());
		m.put("telephone", comment.getTelephone());
		m.put("content", comment.getContent());
		m.put("createTime", comment.getCreateTime());
		m.put("feedback", comment.getFeedback());
		m.put("status", comment.getStatus());
		m.put("createUser", comment.getCreateUser());
		m.put("memberId", comment.getMemberId());
		m.put("cover", comment.getCover());
		m.put("contact", comment.getContact());
		m.put("score  ", comment.getScore());
		if(comment.getMemberId()!=null){
			Member member = publicService.findMember(comment.getMemberId());
			if(member!=null){
				m.put("avatarImg", FILESERVER+member.getAvatarImg());
			}else{
				m.put("avatarImg", "");
			}
			member=null;
		}else{
			m.put("avatarImg", "");
		}
		
		String result = formatToJson(m);
		
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("configList")
	@ResponseBody
	public void configList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String nameCn = request.getParameter("nameCn");
		String nameEn = request.getParameter("nameEn");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (nameCn != null && !"".equals(nameCn)) {
			queryParams.put("%,nameCn", nameCn);
		}
		if (nameEn != null && !"".equals(nameEn)) {
			queryParams.put("=,nameEn", nameEn);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getConfigCount(queryParams);
		List<Config> list = publicService.getConfig(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("configByName")
	@ResponseBody
	public void configByName(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String nameEn = request.getParameter("nameEn");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		queryParams.put("=,nameEn", nameEn);
		queryParams.put("^,id", "desc");
		List<Config> list = publicService.getConfig(queryParams, 1,1);
		Config config=new Config();
		if(list!=null){
			config=list.get(0);
		}
		
		String result = formatToJson(config);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("courseList")
	@ResponseBody
	public void courseList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String name = request.getParameter("name");
		String categoryId = request.getParameter("categoryId");
		String tag = request.getParameter("tag");
		String status = request.getParameter("status");
		String grade = request.getParameter("grade");
		String auditType = request.getParameter("auditType");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name" , name);
		}
		if (categoryId != null && !"".equals(categoryId)) {
			queryParams.put("=,categoryId" , categoryId);
		}
		if (tag != null && !"".equals(tag)) {
			queryParams.put("%,tag" , tag);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status" , status);
		}
		if (grade != null && !"".equals(grade)) {
			queryParams.put("=,grade" , grade);
		}
		if (auditType != null && !"".equals(auditType)) {
			queryParams.put("=,auditType" , auditType);
		}
		User user1 = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		if(!user1.getUsername().equals("root")&&user1.getType()!=0){
			queryParams.put("=,createUser" , user1.getUsername());
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getCourseCount(queryParams);
		List<Course> list = publicService.getCourse(queryParams, pageSize,pageNumber);
		List<Map<String,Object>>listmap=new ArrayList<Map<String,Object>>();
		for (Course course : list) {
			Map<String,Object> m = new HashMap<String, Object>();
			m.put("id", course.getId());
			m.put("name", course.getName());
			m.put("tag", course.getTag());
			m.put("auditType", course.getAuditType());
			m.put("status", course.getStatus());
			
			//-1-已注销 0-待审核 1-审核通过 2-已上架 3-已下架
			/*if(-1==course.getStatus()){
				m.put("status", "已注销");
			}else if(0==course.getStatus()){
				m.put("status", "待审核");
			}else if(1==course.getStatus()){
				m.put("status", "审核通过");
			}else if(2==course.getStatus()){
				m.put("status", "已上架");
			}else if(3==course.getStatus()){
				m.put("status", "已下架");
			}*/
			
			//course_id
			queryParams=null;
			queryParams=new HashMap<String, Object>();
			queryParams.put("=,courseId", course.getId());
			queryParams.put("=,status", "2");
			queryParams.put("=,auditType", "2");
			Integer onlinecount = publicService.getOnlineCount(queryParams);
			List<Online> onlines = publicService.getOnline(queryParams, 1, onlinecount);
			BigDecimal bigDecimal = new BigDecimal(0);
			for (Online online : onlines) {
				bigDecimal=bigDecimal.add( new BigDecimal(online.getPrice()));
			}
			
			m.put("price", bigDecimal);
			
			Category category = publicService.findCategory(course.getCategoryId());
			m.put("categoryId", category.getName());
			category=null;
			String[] split = course.getUserIds().split(";");
			StringBuffer tearchers = new StringBuffer();
			for (String string : split) {
				if(!"".equals(string)){
					User user = publicService.findUser(Integer.parseInt(string));
					if(user.getRealName()!=null && !"".equals(user.getRealName())){
						tearchers.append(user.getRealName()).append(";");
					}else{
						tearchers.append(user.getUsername()).append(";");
					}
					user=null;
				}
			}
			m.put("userIds", tearchers.toString());
			m.put("cover", FILESERVER+course.getCover());
			tearchers=null;
			listmap.add(m);
			m=null;
		}
		
		String result = formatToJson(listmap);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("courseListPass")
	@ResponseBody
	public void courseListPass(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<Course>list = new ArrayList<Course>();
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		/*queryParams.put("=,status", "2");
		queryParams.put("=,auditType", "0");
		List<Map<String, Object>>lm=new ArrayList<Map<String,Object>>();
		Integer count = publicService.getCourseCount(queryParams);
		List<Course> list1 = publicService.getCourse(queryParams, 1,count);
		
		if(list1!=null){
			list.addAll(list1);
		}*/
		
		queryParams=null;
		queryParams = new HashMap<String, Object>();
		queryParams.put("=,status", "2");
		queryParams.put("=,auditType", "2");
		Integer count = publicService.getCourseCount(queryParams);
		List<Course> list2 = publicService.getCourse(queryParams, 1,count);
		if(list2!=null){
			list.addAll(list2);
		}
		
		String result = formatToJson(list);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("getCourseQuestionList")
	@ResponseBody
	public void getCourseQuestionList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Integer courseQuestionListCount = publicService.getCourseQuestionListCount(id);
		List<Map<String, Object>> courseQuestionList = publicService.getCourseQuestionList(id, 1, courseQuestionListCount);
		
		String result = formatToJson(courseQuestionList);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("courseFind")
	@ResponseBody
	public void courseFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Course course = new Course();
		if (id != null && !"".equals(id)) {
			course = publicService.findCourse(Integer.parseInt(id));
		}
		Map<String, Object>m=new HashMap<String, Object>();
		Map<String, Object>m1=new HashMap<String, Object>();
		String[] splits = course.getUserIds().split(";");
		
		for (String string : splits) {
			if(!"".equals(string)){
				User user = publicService.findUser(Integer.parseInt(string));
				if(user.getRealName()!=null && !"".equals(user.getRealName())){
					m1.put(user.getId()+"", user.getRealName());
				}else{
					m1.put(user.getId()+"", user.getUsername());
					
				}
			}
		}
		
		m.put("cover", FILESERVER+course.getCover());
		m.put("categoryId", course.getCategoryId());
		m.put("description", course.getDescription()==null?"":course.getDescription().replace(" src=\"", " src=\""+FILESERVER));
		m.put("grade", course.getGrade());
		m.put("name", course.getName());
		m.put("tag", course.getTag());
		m.put("userIds", m1);
		
		String sb = super.formatToJson(m);
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("courseCommentList")
	@ResponseBody
	public void courseCommentList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		
		String courseId = request.getParameter("courseId");
		String content = request.getParameter("content");
		String telephone = request.getParameter("telephone");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		List<CourseComment> list = new ArrayList<CourseComment>();
		Integer count = 0;
		if (courseId != null && !"".equals(courseId)) {
			queryParams.put("=,courseId" , courseId);
			if (content != null && !"".equals(content)) {
				queryParams.put("%,content" , content);
			}
			if (telephone != null && !"".equals(telephone)) {
				queryParams.put("=,telephone", telephone);
			}
			queryParams.put("^,id", "desc");
			count = publicService.getCourseCommentCount(queryParams);
			list = publicService.getCourseComment(queryParams, pageSize,pageNumber);
			/*for (CourseComment courseComment : list) {
				courseComment.setFeedback("");
			}*/
		}
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("courseQuestionList")
	@ResponseBody
	public void courseQuestionList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		Integer count = publicService.getCourseQuestionCount(queryParams);
		List<CourseQuestion> list = publicService.getCourseQuestion(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("liveList")
	@ResponseBody
	public void liveList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String tag = request.getParameter("tag");
		String status = request.getParameter("status");
		String name = request.getParameter("name");
		String classesOnlineId = request.getParameter("classesOnlineId");
		String auditType = request.getParameter("auditType");
		
		
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		queryParams.put("^,id","desc");
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name",name);
		}
		if (tag != null && !"".equals(tag)) {
			queryParams.put("%,tag",tag);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status",status);
		}
		if (classesOnlineId != null && !"".equals(classesOnlineId)) {
			queryParams.put("=,classesOnlineId",classesOnlineId);
		}
		if (auditType != null && !"".equals(auditType)) {
			queryParams.put("=,auditType",auditType);
		}
		User user1 = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		if(!user1.getUsername().equals("root")&&user1.getType()!=0){
			queryParams.put("=,createUser" , user1.getUsername());
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getLiveCount(queryParams);
		List<Live> list = publicService.getLive(queryParams, pageSize,pageNumber);
		
		List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
    	for (Live live : list) {
    		m= new HashMap<String, Object>();
    		m.put("id", live.getId());
    		m.put("cover", live.getCover());
    		m.put("createTime", live.getCreateTime());
    		m.put("createUser", live.getCreateUser());
    		m.put("description", live.getDescription());
    		m.put("liveEnd", live.getLiveEnd());
    		m.put("liveSource", live.getLiveSource());
    		m.put("liveStart", live.getLiveStart());
    		m.put("name", live.getName());
    		m.put("price", live.getPrice());
    		m.put("status", live.getStatus());
    		m.put("auditType", live.getAuditType());
    		m.put("tag", live.getTag());
    		m.put("liveStatus", live.getLiveStatus());
    		if(live.getClassesOnlineId()!=null && !"".equals(live.getClassesOnlineId())){
    			ClassesOnline classesOnline = publicService.findClassesOnline(live.getClassesOnlineId());
    			m.put("classesOnlineId", classesOnline.getId());
    			m.put("classesOnlineName", classesOnline.getName());
    			classesOnline=null;
    		}else{
    			m.put("classesOnlineId", "");
    			m.put("classesOnlineName", "");
    		}
    		lm.add(m);
    		m=null;
		}
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("liveFind")
	@ResponseBody
	public void liveFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String,Object>m= new HashMap<String, Object>();
		String id = request.getParameter("id");
		if(id!=null && !"".equals(id)){
			Live live = publicService.findLive(Integer.parseInt(id));
			if(live!=null){
				m.put("id", live.getId());
				m.put("cover", FILESERVER+live.getCover());
				m.put("createTime", live.getCreateTime());
				m.put("createUser", live.getCreateUser());
				m.put("description", live.getDescription());
				m.put("liveEnd", live.getLiveEnd());
				m.put("liveSource", live.getLiveSource());
				m.put("liveStart", live.getLiveStart());
				m.put("name", live.getName());
				m.put("price", live.getPrice());
				m.put("status", live.getStatus());
				m.put("tag", live.getTag());
				m.put("liveStatus", live.getLiveStatus());
				if(live.getClassesOnlineId()!=null && !"".equals(live.getClassesOnlineId())){
					ClassesOnline classesOnline = publicService.findClassesOnline(live.getClassesOnlineId());
					m.put("classesOnlineId", classesOnline.getId());
					m.put("classesOnlineName", classesOnline.getName());
					classesOnline=null;
				}else{
					m.put("classesOnlineId", "");
					m.put("classesOnlineName", "");
				}
			}
		}
		String result = formatToJson(m);
		
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	@RequestMapping("liveQuestionList")
	@ResponseBody
	public void liveQuestionList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getLiveQuestionCount(queryParams);
		List<LiveQuestion> list = publicService.getLiveQuestion(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("logList")
	@ResponseBody
	public void logList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String createIpAddress = request.getParameter("createIpAddress");
		String businessType = request.getParameter("businessType");
		String operatorType = request.getParameter("operatorType");
		String createUser = request.getParameter("createUser");
		String telephone = request.getParameter("telephone");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (createIpAddress != null && !"".equals(createIpAddress)) {
			queryParams.put("=,createIpAddress", createIpAddress);
		}
		if (businessType != null && !"".equals(businessType)) {
			queryParams.put("=,businessType", businessType);
		}
		if (operatorType != null && !"".equals(operatorType)) {
			queryParams.put("=,operatorType", operatorType);
		}
		if (createUser != null && !"".equals(createUser)) {
			queryParams.put("=,createUser", createUser);
		}
		if (telephone != null && !"".equals(telephone)) {
			queryParams.put("=,telephone", telephone);
		}
		
		queryParams.put("^,id", "desc");
		Integer count = publicService.getLogCount(queryParams);
		List<Log> list = publicService.getLog(queryParams, pageSize,pageNumber);
		List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
		for (Log log : list) {
			m= new HashMap<String, Object>();
			m.put("id", log.getId());
			m.put("businessType", log.getBusinessType());
			m.put("createIpAddress", log.getCreateIpAddress());
			m.put("createTime", log.getCreateTime());
			m.put("exception", log.getException()==null?"":log.getException());
			m.put("operatorType", log.getOperatorType());
			m.put("params", log.getParams());
			m.put("text", log.getText());
			m.put("uri", log.getUri());
			m.put("createUser", log.getCreateUser());
			m.put("telephone", log.getTelephone());
			lm.add(m);
    		m=null;
		}
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		list=null;
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("memberList")
	@ResponseBody
	public void memberList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String username = request.getParameter("username");
		String nickName = request.getParameter("nickName");
		String telephone = request.getParameter("telephone");
		String status = request.getParameter("status");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (username != null && !"".equals(username)) {
			queryParams.put("=,username", username);
		}
		if (nickName != null && !"".equals(nickName)) {
			queryParams.put("=,nickName", nickName);
		}
		if (telephone != null && !"".equals(telephone)) {
			queryParams.put("=,telephone", telephone);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getMemberCount(queryParams);
		List<Member> list = publicService.getMember(queryParams, pageSize,pageNumber);
		List<Map<String,Object>>lm = new ArrayList<Map<String,Object>>();
		Map<String,Object> m = null;
		
		for (Member member : list) {
			m=new HashMap<String, Object>();
			m.put("id", member.getId());
			m.put("avatarImg", FILESERVER+member.getAvatarImg());
			m.put("createTime", member.getCreateTime());
			m.put("description", member.getDescription());
			m.put("email", member.getEmail());
			m.put("gender", member.getGender());
			m.put("nickName", member.getNickName());
			m.put("signature", member.getSignature());
			m.put("realName", member.getRealName());
			m.put("status", member.getStatus());
			m.put("telephone", member.getTelephone());
			m.put("type", member.getType());
			m.put("username", member.getUsername());
			lm.add(m);
			m=null;
		}
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("messageList")
	@ResponseBody
	public void messageList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String titile = request.getParameter("titile");
		String content = request.getParameter("content");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (titile != null && !"".equals(titile)) {
			queryParams.put("%,titile", titile);
		}
		if (content != null && !"".equals(content)) {
			queryParams.put("%,content", content);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getMessageCount(queryParams);
		List<Message> list = publicService.getMessage(queryParams, pageSize,pageNumber);
		
		
		List<Map<String,Object>>lm = new ArrayList<Map<String,Object>>();
		Map<String,Object> m = null;
		for (Message message : list) {
			m=new HashMap<String, Object>();
			m.put("id", message.getId());
			m.put("content", message.getContent()==null?"":message.getContent().replace(" src=\"", " src=\""+FILESERVER));
			m.put("cover", message.getCover());
			m.put("createTime", message.getCreateTime());
			m.put("createUser", message.getCreateUser());
			m.put("status", message.getStatus());
			m.put("title", message.getTitle());
			lm.add(m);
			m=null;
		}
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("messageFind")
	@ResponseBody
	public void messageFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		Message message = new Message();
		Map<String, Object> m = new HashMap<String, Object>();
		if(id!=null && !"".equals(id)){
			message=publicService.findMessage(Integer.parseInt(id));
			m.put("id", message.getId());
			m.put("content", message.getContent()==null?"":message.getContent().replace(" src=\"", " src=\""+FILESERVER));
			m.put("cover", FILESERVER+message.getCover());
			m.put("title", message.getTitle());
		}
		String result = formatToJson(m);
		m=null;
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("onlineList")
	@ResponseBody
	public void onlineList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String courseId = request.getParameter("courseId");
		String tag = request.getParameter("tag");
		String name = request.getParameter("name");
		String status = request.getParameter("status");
		String auditType = request.getParameter("auditType");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name", name);
		}
		if (tag != null && !"".equals(tag)) {
			queryParams.put("%,tag", tag);
		}
		if (courseId != null && !"".equals(courseId)) {
			queryParams.put("=,courseId", courseId);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		if (auditType != null && !"".equals(auditType)) {
			queryParams.put("=,auditType", auditType);
		}
		
		User user1 = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		if(!user1.getUsername().equals("root")&&user1.getType()!=0){
			queryParams.put("=,createUser" , user1.getUsername());
		}
		
		queryParams.put("^,id", "desc");
		Integer count = publicService.getOnlineCount(queryParams);
		List<Online> list = publicService.getOnline(queryParams, pageSize,pageNumber);
		List<Map<String,Object>>lm = new ArrayList<Map<String,Object>>();
		Map<String,Object> m = null;
		for (Online online : list) {
			m = new HashMap<String, Object>();
			Integer courseIid = online.getCourseId();
			if(courseIid!=null && !"".equals(courseIid)){
				Course course = publicService.findCourse(courseIid);
				m.put("courseName", course.getName());
				course.getName();
			}
			m.put("id", online.getId());
			m.put("courseId", online.getCourseId());
			m.put("createTime", online.getCreateTime());
			m.put("createUser", online.getCreateUser());
			m.put("description", online.getDescription());
			m.put("name", online.getName());
			m.put("pdfPath", online.getPdfPath());
			m.put("pptPath", online.getPptPath());
			m.put("price", online.getPrice());
			m.put("status", online.getStatus());
			m.put("auditType", online.getAuditType());
			m.put("tag", online.getTag());
			m.put("type", online.getType());
			m.put("videoPath", online.getVideoPath());
			m.put("pptFilePath", online.getPptFilePath());
			m.put("pdfFilePath", online.getPdfFilePath());
			lm.add(m);
			m=null;
		}
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("onlineFind")
	@ResponseBody
	public void onlineFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		
		Map<String,Object> m = new HashMap<String, Object>();
		if (id != null && !"".equals(id)) {
			Online online = publicService.findOnline(Integer.parseInt(id));
			Integer courseIid = online.getCourseId();
			if(courseIid!=null && !"".equals(courseIid)){
				Course course = publicService.findCourse(courseIid);
				m.put("courseName", course.getName());
				course.getName();
			}
			m.put("id", online.getId());
			m.put("courseId", online.getCourseId());
			m.put("createTime", online.getCreateTime());
			m.put("createUser", online.getCreateUser());
			m.put("description", online.getDescription());
			m.put("name", online.getName());
			m.put("pdfPath", online.getPdfPath());
			m.put("pptPath", online.getPptPath());
			m.put("price", online.getPrice());
			m.put("status", online.getStatus());
			m.put("tag", online.getTag());
			m.put("type", online.getType());
			m.put("videoPath", online.getVideoPath());
			m.put("pptFilePath", (online.getPptFilePath()==null || "".equals(online.getPptFilePath()))?"":(FILEPATH+online.getPptFilePath()));
			m.put("pdfFilePath", (online.getPdfFilePath()==null || "".equals(online.getPdfFilePath()))?"":(FILEPATH+online.getPdfFilePath()));
			
			
			
		}
		String result = formatToJson(m);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("onlineQuestionList")
	@ResponseBody
	public void onlineQuestionList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getOnlineQuestionCount(queryParams);
		List<OnlineQuestion> list = publicService.getOnlineQuestion(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("orderList")
	@ResponseBody
	public void orderList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String orderNumber = request.getParameter("orderNumber");
		String status = request.getParameter("status");
		String type = request.getParameter("type");
		String username = request.getParameter("username");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (orderNumber != null && !"".equals(orderNumber)) {
			queryParams.put("=,orderNumber", orderNumber);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		if (type != null && !"".equals(type)) {
			queryParams.put("=,type", type);
		}
		if (username != null && !"".equals(username)) {
			HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
			queryParams1.put("=,username", username);
			List<Member> members = publicService.getMember(queryParams1, 1, 1);
			if(members!=null && members.size()>0){
				queryParams.put("=,memberId", members.get(0).getId());
			}
		}
		if (startTime != null && !"".equals(startTime)) {
			queryParams.put(">=,createTime", startTime);
		}
		if (endTime != null && !"".equals(endTime)) {
			queryParams.put("<=,createTime", endTime);
		}
		
		queryParams.put("^,id", "desc");
		Integer count = publicService.getOrderCount(queryParams);
		List<Order> orders = publicService.getOrder(queryParams, pageSize,pageNumber);

		
		List<Map<String,Object>> lm = new ArrayList<Map<String,Object>>();
    	Map<String,Object> m = null;
    	for (Order order : orders) {
    		m=new HashMap<String, Object>();
    		m.put("id", order.getId());
    		m.put("createTime", order.getCreateTime());
    		m.put("memberId", order.getMemberId());
    		m.put("type", order.getType());
    		m.put("resourceId", order.getResourceId());
    		m.put("orderNumber", order.getOrderNumber());
    		m.put("payPrice", order.getPayPrice());
    		m.put("payWay", order.getPayWay());
    		m.put("createIpAddress", order.getCreateIpAddress());
    		m.put("status", order.getStatus());
    		Member user = publicService.findMember(order.getMemberId());
			if(user!=null){
				m.put("username", user.getUsername());
			}
			user=null;
    		if(0==order.getType()){
    			//课程
    			Course course = publicService.findCourse(order.getResourceId());
    			if(course!=null){
    				m.put("name", course.getName());
    			}
    			course=null;
    		}else if(1==order.getType()){
    			//微课
    			Online online = publicService.findOnline(order.getResourceId());
    			if(online!=null){
    				m.put("name", online.getName());
    			}
    			online=null;
    		}else if(2==order.getType()){
    			//直播
    			Live live = publicService.findLive(order.getResourceId());
    			if(live!=null){
    				m.put("name", live.getName());
    			}
    			live=null;
    		}
    		lm.add(m);
    		m=null;
    	}
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = lm.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("questionList")
	@ResponseBody
	public void questionList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String name = request.getParameter("name");
		String questionDatabaseId = request.getParameter("questionDatabaseId");
		String type = request.getParameter("type");
		String status = request.getParameter("status");
		String auditType = request.getParameter("auditType");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name", name);
		}
		if (questionDatabaseId != null && !"".equals(questionDatabaseId)) {
			queryParams.put("=,questionDatabaseId", questionDatabaseId);
		}
		if (type != null && !"".equals(type)) {
			queryParams.put("=,type", type);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		if (auditType != null && !"".equals(auditType)) {
			queryParams.put("=,auditType", auditType);
		}
		User user1 = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		if(!user1.getUsername().equals("root")&&user1.getType()!=0){
			queryParams.put("=,createUser" , user1.getUsername());
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getQuestionCount(queryParams);
		List<Question> list = publicService.getQuestion(queryParams, pageSize,pageNumber);
		
		List<Map<String, Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String, Object>m=null;
		for (Question question : list) {
			m=new HashMap<String, Object>();
			m.put("id", question.getId());
			m.put("name", question.getName());
			m.put("questionDatabaseId", question.getQuestionDatabaseId());
			m.put("status", question.getStatus());
			m.put("auditType", question.getAuditType());
			m.put("type", question.getType());
			
			QuestionDatabase findQuestionDatabase = publicService.findQuestionDatabase(question.getQuestionDatabaseId());
			if(findQuestionDatabase!=null){
				m.put("questionDatabaseName", findQuestionDatabase.getName());
			}
			findQuestionDatabase=null;
			
			lm.add(m);
			m=null;
		}
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("questionFind")
	@ResponseBody
	public void questionFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Question question = new Question();
		Map<String,Object>m=new HashMap<String, Object>();
		if(id!=null && !"".equals(id)){
			question = publicService.findQuestion(Integer.parseInt(id));
		}
		m.put("id", question.getId());
		m.put("analysis", (question.getAnalysis()==null || "".equals(question.getAnalysis()))?"":(FILESERVER+question.getAnalysis()));
		m.put("answer0", question.getAnswer0());
		m.put("answer1", question.getAnswer1());
		m.put("answer2", question.getAnswer2());
		m.put("name", question.getName());
		m.put("options", question.getOptions());
		m.put("questionDatabaseId", question.getQuestionDatabaseId());
		m.put("type", question.getType());
		m.put("status", question.getStatus());
		m.put("createTime", question.getCreateTime());
		m.put("createUser", question.getCreateUser());
		String result = formatToJson(m);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("questionDatabaseList")
	@ResponseBody
	public void questionDatabaseList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String name = request.getParameter("name");
		String tag = request.getParameter("tag");
		String type = request.getParameter("type");
		String auditType = request.getParameter("auditType");
		String status = request.getParameter("status");
		
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name", name);
		}
		if (tag != null && !"".equals(tag)) {
			queryParams.put("%,tag", tag);
		}
		if (type != null && !"".equals(type)) {
			queryParams.put("=,type", type);
		}
		if (auditType != null && !"".equals(auditType)) {
			queryParams.put("=,auditType", auditType);
		}
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		
		User user1 = publicService.findUser((Integer) request.getSession().getAttribute("userid"));
		if(!user1.getUsername().equals("root")&&user1.getType()!=0){
			queryParams.put("=,createUser" , user1.getUsername());
		}
		
		queryParams.put("^,id", "desc");
		Integer count = publicService.getQuestionDatabaseCount(queryParams);
		List<QuestionDatabase> list = publicService.getQuestionDatabase(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("questionDatabaseListPass")
	@ResponseBody
	public void questionDatabaseListPass(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<QuestionDatabase>list = new ArrayList<QuestionDatabase>();
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		/*queryParams.put("=,status", "2");
		queryParams.put("=,auditType", "0");
		List<Map<String, Object>>lm=new ArrayList<Map<String,Object>>();
		Integer count = publicService.getQuestionDatabaseCount(queryParams);
		List<QuestionDatabase> list1 = publicService.getQuestionDatabase(queryParams, 1,count);
		
		if(list1!=null){
			list.addAll(list1);
		}*/
		
		queryParams=null;
		queryParams = new HashMap<String, Object>();
		queryParams.put("=,status", "2");
		queryParams.put("=,auditType", "2");
		Integer count = publicService.getQuestionDatabaseCount(queryParams);
		List<QuestionDatabase> list2 = publicService.getQuestionDatabase(queryParams, 1,count);
		if(list2!=null){
			list.addAll(list2);
		}
		
		String result = formatToJson(list);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("questionDatabaseAll")
	@ResponseBody
	public void questionDatabaseAll(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String status = request.getParameter("status");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (status != null && !"".equals(status)) {
			queryParams.put("=,status", status);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getQuestionDatabaseCount(queryParams);
		List<QuestionDatabase> list = publicService.getQuestionDatabase(queryParams, 1,count);
		List<Map<String, Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String, Object>m=null;
		for (QuestionDatabase questionDatabase : list) {
			m=new HashMap<String, Object>();
			m.put("id", questionDatabase.getId());
			m.put("name", questionDatabase.getName());
			lm.add(m);
			m=null;
		}
		String result = formatToJson(list);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("questionDatabaseFind")
	@ResponseBody
	public void questionDatabaseFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		QuestionDatabase database = new QuestionDatabase();
		if (id != null && !"".equals(id)) {
			database = publicService.findQuestionDatabase(Integer.parseInt(id));
		}
		String result = formatToJson(database);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("shortFilmList")
	@ResponseBody
	public void shortFilmList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String name = request.getParameter("name");
		String telephone = request.getParameter("telephone");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (name != null && !"".equals(name)) {
			queryParams.put("%,name", name);
		}
		if (telephone != null && !"".equals(telephone)) {
			queryParams.put("=,telephone", telephone);
		}
		queryParams.put("^,id", "desc");
		List<Map<String,Object>>lm = new ArrayList<Map<String,Object>>();
		Integer count = publicService.getShortFilmCount(queryParams);
		List<ShortFilm> list = publicService.getShortFilm(queryParams, pageSize,pageNumber);
		for (ShortFilm shortFilm : list) {
			Map<String,Object> m = new HashMap<String, Object>();
			m.put("id", shortFilm.getId());
			m.put("status", shortFilm.getStatus());
			m.put("description", shortFilm.getDescription());
			m.put("filePath", FILESERVER+shortFilm.getFilePath());
			m.put("memberId", shortFilm.getMemberId());
			
			if(shortFilm.getMemberId()!=null && !"".equals(shortFilm.getMemberId())){
				Member member = publicService.findMember(Integer.parseInt(shortFilm.getMemberId()));
				if(member!=null){
					if(member.getRealName()!=null && !"".equals(member.getRealName())){
						m.put("memberName", member.getRealName());
					}else{
						m.put("memberName", member.getUsername());
					}
				}
				member=null;
			}
			lm.add(m);
			m=null;
		}
		
		String result = formatToJson(lm);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("shortFilmFilePath")
	@ResponseBody
	public void shortFilmFilePath(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		
		String filePath="";
		if (id != null && !"".equals(id)) {
			ShortFilm shortFilm = publicService.findShortFilm(Integer.parseInt(id));
			filePath = FILESERVER+shortFilm.getFilePath();
		}
		super.pringWriterToPage(filePath, "application/json", response);
	}
	@RequestMapping("shortFilmCommentList")
	@ResponseBody
	public void shortFilmCommentList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getShortFilmCommentCount(queryParams);
		List<ShortFilmComment> list = publicService.getShortFilmComment(queryParams, pageSize,pageNumber);
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("paperList")
	@ResponseBody
	public void paperList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String title = request.getParameter("title");
		String description = request.getParameter("description");
		String type = request.getParameter("type");
		String resourceId = request.getParameter("resourceId");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (title != null && !"".equals(title)) {
			queryParams.put("%,title", title);
		}
		if (description != null && !"".equals(description)) {
			queryParams.put("%,description", description);
		}
		if (resourceId != null && !"".equals(resourceId)) {
			queryParams.put("=,resourceId", resourceId);
		}
		if (type != null && !"".equals(type)) {
			queryParams.put("=,type", type);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getPaperCount(queryParams);
		List<Paper> list = publicService.getPaper(queryParams, pageSize,pageNumber);
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	@RequestMapping("paperFind")
	@ResponseBody
	public void paperFind(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Paper paper = new Paper();
		if(id!=null&&!"".equals(id)&&!"0".equals(id)){
			paper = publicService.findPaper(Integer.parseInt(id));
		}
		String result = formatToJson(paper);
		super.pringWriterToPage(result, "application/json", response);
	}
	@RequestMapping("answerList")
	@ResponseBody
	public void answerList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Integer pageNumber = 15;
		String pn = request.getParameter("pageSize");
		if(pn!=null && !"".equals(pn)){
			pageNumber=Integer.parseInt(pn);
		}
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String queryParam = request.getParameter("queryParams");
		String text = request.getParameter("text");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (text != null && !"".equals(text)) {
			queryParams.put("%," + queryParam, text);
		}
		queryParams.put("^,id", "desc");
		Integer count = publicService.getAnswerCount(queryParams);
		List<Answer> list = publicService.getAnswer(queryParams, pageSize,pageNumber);
		
		String result = formatToJson(list);
		StringBuffer sb = new StringBuffer();
		int listsize = list.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	
	@RequestMapping("getLiveQuestionList")
	@ResponseBody
	public void getLiveQuestionList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Integer liveQuestionListCount = publicService.getLiveQuestionListCount(id);
		List<Map<String, Object>> liveQuestionList = publicService.getLiveQuestionList(id, 1, liveQuestionListCount);
		
		String result = formatToJson(liveQuestionList);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	@RequestMapping("getOnlineQuestionList")
	@ResponseBody
	public void getOnlineQuestionList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Integer onlineQuestionListCount = publicService.getOnlineQuestionListCount(id);
		List<Map<String, Object>> onlineQuestionList = publicService.getOnlineQuestionList(id, 1, onlineQuestionListCount);
		
		String result = formatToJson(onlineQuestionList);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	@RequestMapping("getAuditList")
	@ResponseBody
	public void getAuditList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String type = request.getParameter("type");
		String resourceId = request.getParameter("resourceId");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (type != null && !"".equals(type)) {
			queryParams.put("=,type", type);
		}
		if (resourceId != null && !"".equals(resourceId)) {
			queryParams.put("=,resourceId", resourceId);
		}
		queryParams.put("^,id", "asc");
		
		Integer auditCount = publicService.getAuditCount(queryParams);
		List<Audit> audits = publicService.getAudit(queryParams, 1, auditCount);
		
		String result = formatToJson(audits);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	/**
	 * type 0-课程 1-题目 2-网班,3-直播，4-微课，5-广告，6-题库
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("getSimilarity")
	@ResponseBody
	public void getSimilarity(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		String type = request.getParameter("type");
		String auditType = request.getParameter("auditType");
		HashMap<String, String>r=new HashMap<String, String>();
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if("0".equals(type)){//课程
			if("1".equals(auditType)){
				queryParams.put("=,type", "0");
				queryParams.put("=,resourceId", id);
				Integer orderCount = publicService.getOrderCount(queryParams);
				if(orderCount!=null && orderCount>0){
					r.put("result", "fail");
					r.put("msg", "课程已被购买，不能【注销审核】");
				}
			}
			if(r.isEmpty()){
				queryParams=null;
				queryParams = new HashMap<String, Object>();
				Course course = publicService.findCourse(Integer.parseInt(id));
				queryParams.put("=,name", course.getName());
				queryParams.put("=,grade", course.getGrade());
				queryParams.put("=,categoryId", course.getCategoryId());
				Integer courseCount = publicService.getCourseCount(queryParams);
				if(courseCount!=null && courseCount>1){
					r.put("result", "fail");
					r.put("msg", "有类似课程：请在列表页根据【名称、栏目、学段】搜索查看");
				}else{
					r.put("result", "success");
					r.put("msg", "没有类似成功");
				}
			}
		}else if("1".equals(type)){
			if("1".equals(auditType)){
				queryParams.put("=,questionId", id);
				Integer orderCount = publicService.getCourseQuestionCount(queryParams);
				if(orderCount!=null && orderCount>0){
					r.put("result", "fail");
					r.put("msg", "课程中使用，不能【注销审核】");
				}else{
					orderCount = publicService.getOnlineQuestionCount(queryParams);
					if(orderCount!=null && orderCount>0){
						r.put("result", "fail");
						r.put("msg", "微课中使用，不能【注销审核】");
					}else{
						orderCount = publicService.getOnlineQuestionCount(queryParams);
						if(orderCount!=null && orderCount>0){
							r.put("result", "fail");
							r.put("msg", "直播中使用，不能【注销审核】");
						}else{
							
						}
					}
				}
			}
			if(r.isEmpty()){
				queryParams=null;
				queryParams = new HashMap<String, Object>();
				Question course = publicService.findQuestion(Integer.parseInt(id));
				queryParams.put("=,name", course.getName());
				queryParams.put("=,type", course.getType());
				Integer courseCount = publicService.getQuestionCount(queryParams);
				if(courseCount!=null && courseCount>1){
					r.put("result", "fail");
					r.put("msg", "有类似题目：请在列表页根据【名称、类型】搜索查看");
				}else{
					r.put("result", "success");
					r.put("msg", "没有类似成功");
				}
			}
			
			
		}else if("2".equals(type)){
			if("1".equals(auditType)){
				queryParams.put("=,classesOnlineId", id);
				Integer liveCount = publicService.getLiveCount(queryParams);
				List<Live> lives = publicService.getLive(queryParams, 1, liveCount);
				for (Live live : lives) {
					queryParams=null;
					queryParams=new HashMap<String, Object>();
					queryParams.put("=,type", "2");
					queryParams.put("=,resourceId", live.getId());
					Integer orderCount = publicService.getOrderCount(queryParams);
					if(orderCount!=null && orderCount>0){
						r.put("result", "fail");
						r.put("msg", "关联直播已被购买，不能【注销审核】");
						break;
					}
				}
				
			}
			if(r.isEmpty()){
				r.put("result", "success");
				r.put("msg", "没有类似成功");
			}
		}else if("3".equals(type)){
			if("1".equals(auditType)){
				queryParams=null;
				queryParams=new HashMap<String, Object>();
				queryParams.put("=,type", "2");
				queryParams.put("=,resourceId", id);
				Integer orderCount = publicService.getOrderCount(queryParams);
				if(orderCount!=null && orderCount>0){
					r.put("result", "fail");
					r.put("msg", "直播已被购买，不能【注销审核】");
				}
				
			}
			if(r.isEmpty()){
				r.put("result", "success");
				r.put("msg", "没有类似成功");
			}
		}else if("4".equals(type)){//微课
			if("1".equals(auditType)){
				queryParams.put("=,type", "1");
				queryParams.put("=,resourceId", id);
				Integer orderCount = publicService.getOrderCount(queryParams);
				if(orderCount!=null && orderCount>0){
					r.put("result", "fail");
					r.put("msg", "微课已被购买，不能【注销审核】");
				}else{
					r.put("result", "success");
					r.put("msg", "没有类似成功");
				}
			}else{
				r.put("result", "success");
				r.put("msg", "没有类似成功");
			}
		}else if("5".equals(type)){
			
		}else if("6".equals(type)){
			if("1".equals(auditType)){
				Integer courseOrderQuetionBaseCount = publicService.courseOrderQuetionBaseCount(id);
				if(courseOrderQuetionBaseCount!=null && courseOrderQuetionBaseCount>0){
					r.put("result", "fail");
					r.put("msg", "在【课程】中已被购买，不能【注销审核】");
				}else{
					Integer onlineOrderQuetionBaseCount = publicService.onlineOrderQuetionBaseCount(id);
					if(onlineOrderQuetionBaseCount!=null && onlineOrderQuetionBaseCount>0){
						r.put("result", "fail");
						r.put("msg", "在【微课】中已被购买，不能【注销审核】");
					}
				}
			}
			if(r.isEmpty()){
				queryParams=null;
				queryParams = new HashMap<String, Object>();
				QuestionDatabase course = publicService.findQuestionDatabase(Integer.parseInt(id));
				queryParams.put("=,name", course.getName());
				queryParams.put("=,type", course.getType());
				Integer courseCount = publicService.getQuestionDatabaseCount(queryParams);
				if(courseCount!=null && courseCount>1){
					r.put("result", "fail");
					r.put("msg", "有类似题库：请在列表页根据【题库名称、学科名称】搜索查看");
				}else{
					r.put("result", "success");
					r.put("msg", "没有类似成功");
				}
			}
		}
		
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	@RequestMapping("toExcel")
	@ResponseBody
	public void toExcel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String createIpAddress = request.getParameter("createIpAddress");
		String businessType = request.getParameter("businessType");
		String operatorType = request.getParameter("operatorType");
		String createUser = request.getParameter("createUser");
		String telephone = request.getParameter("telephone");
		
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if (createIpAddress != null && !"".equals(createIpAddress)) {
			queryParams.put("=,createIpAddress", createIpAddress);
		}
		if (businessType != null && !"".equals(businessType)) {
			queryParams.put("=,businessType", businessType);
		}
		if (operatorType != null && !"".equals(operatorType)) {
			queryParams.put("=,operatorType", operatorType);
		}
		if (createUser != null && !"".equals(createUser)) {
			queryParams.put("=,createUser", createUser);
		}
		if (telephone != null && !"".equals(telephone)) {
			queryParams.put("=,telephone", telephone);
		}
		
		queryParams.put("^,id", "desc");
		Integer count = publicService.getLogCount(queryParams);
		List<Log> list = publicService.getLog(queryParams, 1,count);
		List<HashMap<String,Object>>lm=new ArrayList<HashMap<String,Object>>();
		HashMap<String,Object>m=null;
		for (Log log : list) {
			m= new HashMap<String, Object>();
			m.put("id", log.getId());
			m.put("businessType", log.getBusinessType());
			m.put("createIpAddress", log.getCreateIpAddress());
			m.put("createTime", log.getCreateTime());
			m.put("exception", log.getException()==null?"":log.getException());
			m.put("operatorType", log.getOperatorType());
			m.put("params", log.getParams());
			m.put("text", log.getText());
			m.put("uri", log.getUri());
			m.put("createUser", log.getCreateUser());
			m.put("telephone", log.getTelephone());
			lm.add(m);
    		m=null;
		}
		String path = request.getSession().getServletContext().getRealPath("/")+"log_excel/";
		if(!new File(path).exists()){
			new File(path).mkdirs();
		} 
		path=path+System.currentTimeMillis()+".xlsx";
		System.out.println(path);
		ExcelUtils.createExcelFile(lm, path);
		super.pringWriterToPage(path, "application/json", response);
	}
	@RequestMapping("logDownLoad")
	@ResponseBody
	public void logDownLoad(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String path = request.getParameter("path");
		FileDownloadUtil.download(path, null, request, response);
	}
}
